const connection = require('../app/database')
class userService {
  async create(user) {
    const { name, password } = user
    // 获取用户
    // 将user对象保存到数据库中
    const statement = 'INSERT INTO `user`(name,password) VALUES(?,?);'
    const result = await connection.execute(statement, [name, password])
    return result
    // user表
  }
  async findUserByName(name) {
    const statement = 'SELECT * FROM `user`WHERE name = ?;'
    const [values] = await connection.execute(statement, [name])
    // console.log(values)
    return values
    // console.log(result)
  }
  async updateUserAvatar(avatarUrl,userId){
    // console.log(333)
    const statement = 'UPDATE user SET avatar_url=? WHERE id=?;'
    const [values] = await connection.execute(statement, [avatarUrl,userId])
    // console.log(values)
    return values

  }
}
module.exports = new userService()
